#!/bin/bash

# download nerdctl
# wget https://github.com/containerd/nerdctl/releases/download/v1.0.0/nerdctl-1.0.0-linux-amd64.tar.gz
wget https://gitee.com/deviltofree/nerdctl/releases/download/v1.0.0/nerdctl-1.0.0-linux-amd64.tar.gz


mkdir -p /usr/local/containerd/bin/
tar -zxvf nerdctl-1.0.0-linux-amd64.tar.gz -C /usr/local/containerd/bin/

ln -s /usr/local/containerd/bin/nerdctl /usr/local/bin/nerdctl

# download buildkit
wget https://gitee.com/deviltofree/buildkit/releases/download/v0.10.5/buildkit-v0.10.5.linux-amd64.tar.gz

tar -zxvf buildkit-v0.10.5.linux-amd64.tar.gz -C /usr/local/containerd/

ln -s /usr/local/containerd/bin/buildkitd /usr/local/bin/buildkitd
ln -s /usr/local/containerd/bin/buildctl /usr/local/bin/buildctl

# use systemd
cat <<EOF >  /etc/systemd/system/buildkit.service
[Unit]
Description=BuildKit
Documentation=https://github.com/moby/buildkit

[Service]
ExecStart=/usr/local/bin/buildkitd --oci-worker=false --containerd-worker=true

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload

systemctl enable buildkit --now

systemctl status buildkit


